package hui.com.controller.perms;

import hui.com.model.entity.PermsEntity;
import hui.com.model.res.MyResponse;
import hui.com.service.PermsService;
import hui.com.service.UserLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin(origins = "*")//处理跨源资源共享
@RequestMapping("/public/perms")
@Controller
public class perms {
    @Resource
    PermsService permsService;

    /**
     * 模糊查询权限集
     */
    @RequestMapping("/getPermsList")
    @ResponseBody
    public Object getPermsList(@RequestBody(required = false) PermsEntity perms){
        if (perms==null){
            perms = new PermsEntity();
        }
        return MyResponse.builder().data(permsService.getPermsList(perms)).code(200).build();
    }


    /**
     * 获取用户指定的权限
     */
    @RequestMapping("/getUserPermsCode")
    @ResponseBody
    public Object getUserPermsCode(@RequestBody Integer id) {
        return MyResponse.builder().data(permsService.getUserPermsCode(id)).code(200).build();
    }

    /**
     * 获取用户所有角色的所有权限
     */
    @RequestMapping("/getUserRolePermsCode")
    @ResponseBody
    public Object getUserRolePermsCode(@RequestBody Integer id) {
        return MyResponse.builder().data(permsService.getUserRolePermsCode(id)).code(200).build();
    }

}
